<!--
 * @Author: 刘十三
 * @Date: 2024-01-02 17:02:25
 * @LastEditors: 刘十三
 * @LastEditTime: 2024-02-26 15:10:04
 * @FilePath: \NM-dev-1.3.1\dev\pages\internal\linkage\components\flowUserList.vue
 * @Description: 内蒙多员联动 - 信息录入、信息录入审批、延期办理申请（选择审批人）
-->

<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
      <view class="nav-right-icon" v-if="tabIndex == 0">
        <text @tap="save">
          确定
        </text>
      </view>
    </theme-navbar>
    <!-- #endif -->
    <!-- #ifdef H5-WECHAT -->
    <fab-button :content="fContent" @fabtrigger="fabtrigger" />
    <!-- #endif -->
    <view class="content u-page">
      <view class="select-lay">
        <view class="sel-desc">
          已选择：
        </view>
        <view class="select-users">
          <u-tag class="u-m-r-15" type="info" :closeable="true" :text="personName" @close="deleteSelectUser" v-if="value"></u-tag>
        </view>
      </view>
      <u-radio-group v-model="value" @change="checkboxChange" style="width: 100%">
        <list-view :i="0" :index="0" :load-data="loadData" :init-load="false" :height="getListViewHeight()" :fixed="false" :justScroll="true" ref="mescrollItem0" style="width:100%">
          <view class="n-lay" slot-scope="d">
            <view class="item-checkbox item-content">
              <u-radio :name="d.data.personId" :size="50" shape="square">{{ d.data.personName }}({{ d.data.deptName }})</u-radio>
            </view>
          </view>
        </list-view>
      </u-radio-group>
    </view>
  </view>
</template>

<script>
import listView from "@/components/list_view.vue";
import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
import linkageService from "@/service/internal/linkeage.service";
import fabButton from "@/components/uni-fab.vue";

export default {
  onLoad(opt) {
    this.status = opt.status;
    this.gfCode = opt.gfCode;
    this.bizId = opt.bizId;
    this.index = opt.index;
    this.isTansfer = opt.isTansfer;
    this.orgId = opt.orgId ? opt.orgId : "";
    this.categoryParentCode = opt.categoryParentCode ? opt.categoryParentCode : "";
    this.longitude = opt.longitude || "";
    this.latitude = opt.latitude || "";
    this.needLevel = opt.needLevel == "0" ? false : true; // 是否需要level 字段作为参数
    this.tdmId = opt.tdmId || "";
    this.transactOrgId = opt.transactOrgId || "";
  },
  components: {
    listView,
    fabButton,
  },
  mixins: [MescrollMoreMixin],
  data() {
    return {
      gfCode: "",
      bizId: "",
      personList: [],
      personName: "",
      needLevel: true,
      user: this.$store.state.userInfo,
      fContent: [
        {
          iconPath: require("@/static/confirm.png"),
          selectedIconPath: require("@/static/confirm.png"),
          text: "确定",
          active: false,
        },
      ],
      value: "",
    };
  },
  mounted() {
    this.$refs["mescrollItem0"].$refs["mescrollRef0"].downHight = 0;
    this.setRightBtns();
  },
  methods: {
    setRightBtns() {
      // 设置右侧标题
      // #ifdef H5-DINGDING
      let self = this;
      this.$deviceApi.setRight(
        "确定",
        () => {
          self.save();
          this.setRightBtns();
        },
        true,
        true
      );
      // #endif
    },
    fabtrigger(btn) {
      if (btn.index == 0) {
        this.save();
      }
    },
    checkboxChange(e) {
      this.personName = this.personList.find((item) => item.personId == this.value)["personName"];
    },
    // 删除选中人员
    deleteSelectUser(ua) {
      let self = this;
      this.$modal.alert("确认删除吗？", "提示", () => {}, "确定", true);
    },
    getListViewHeight() {
      let p = this.$u.sys().windowHeight - 44 - uni.upx2px(180) - this.$u.sys().statusBarHeight + "px";
      // #ifdef H5-DINGDING || H5-WECHAT
      p = uni.upx2px(180) + "px";
      // #endif
      return p;
    },
    save() {
      if (!this.value) {
        this.$modal.alert("请选择人员");
        return;
      }
      this.backPrev({
        paramKey: "flowUserSelectBack",
        param: this.value,
      });
    },
    loadData(page) {
      let queryParams = {};
      queryParams.gfCode = this.gfCode;
      queryParams.processDefKey = this.gfCode;
      queryParams.bizId = this.bizId || "";
      queryParams.limit = 100;
      queryParams.page = 1;
      let self = this;
      let aiaxName = "";
      self.$modal.showLoading("加载中...");
      if (self.status == "3" && self.index == "3") {
        let extraParam = {
          reqParam: {
            isTansfer: this.isTansfer ? Number(this.isTansfer) : 0,
          },
        };
        Object.assign(queryParams, extraParam);
      }
      if (self.status == "1") {
        queryParams.categoryParentCode = self.categoryParentCode;
        queryParams.retailerIssueOrgId = self.orgId;
        queryParams.longitude = self.longitude;
        queryParams.latitude = self.latitude;
        aiaxName = "getNextFlowUsersNM";
      } else if (self.status == "2") {
        aiaxName = "getNextFlowUsersYQ";
      } else if (self.status == "3") {
        aiaxName = "getNextFlowUsersNM";
      } else if (self.status == "4") {
        queryParams.tdmId = self.tdmId;
        queryParams.transactOrgId = self.transactOrgId;
        aiaxName = "getNextFlowUsersTask";
      }
      return new Promise((resolve, reject) => {
        linkageService[aiaxName](queryParams)
          .then((dr) => {
            self.$modal.hideLoading();
            if (dr.success) {
              this.personList = dr.data;
              resolve({
                data: {
                  list: [...dr.data],
                  totalCount: dr.data.length,
                },
              });
            } else {
              resolve({
                data: {
                  list: [],
                  totalCount: 0,
                },
              });
            }
          })
          .catch((err) => {
            self.$modal.hideLoading();
            resolve({
              data: {
                list: [],
                totalCount: 0,
              },
            });
          });
      });
    },
  },
};
</script>

<style scoped lang="scss">
.n-lay {
  width: 100%;
  display: block;
  padding: 20rpx 20rpx;
  border-bottom: 1px solid $u-border-color;
}

.select-lay {
  padding: 20rpx 20rpx;
  border-bottom: 1px solid $u-bg-color;
}

.sel-desc {
  margin-top: 32rpx;
  color: #999999;
  font-size: 15px;
}

.select-users {
  height: 28px;
  margin-top: 30rpx;

  uni-text {
    color: #027aff;
    background: #e6f1ff;
    width: auto;
    font-size: 15px;
    font-weight: bold;
    // border: 1px solid #1fa3ff;
    border-radius: 16px;
    padding: 3px;
    margin: 3px;
  }
}

.nav-right-icon {
  margin-right: 30rpx;
  font-size: 0.8rem;
  color: #fff;
}
</style>
